package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PersonMgt;
import com.ruoyi.system.service.IPersonMgtService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * PersonMgtController
 */
@Anonymous
@RestController
@RequestMapping("/system/mgt")
public class PersonMgtController extends BaseController
{
    @Autowired
    private IPersonMgtService personMgtService;

    /**
     * 查询人员管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:mgt:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonMgt personMgt)
    {
        startPage();
        List<PersonMgt> list = personMgtService.selectPersonMgtList(personMgt);
        return getDataTable(list);
    }

    /**
     * 导出人员管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:mgt:export')")
    @Log(title = "人员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonMgt personMgt)
    {
        List<PersonMgt> list = personMgtService.selectPersonMgtList(personMgt);
        ExcelUtil<PersonMgt> util = new ExcelUtil<PersonMgt>(PersonMgt.class);
        util.exportExcel(response, list, "人员管理数据");
    }

    /**
     * 获取人员管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:mgt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(personMgtService.selectPersonMgtById(id));
    }

    /**
     * 新增人员管理
     */
    //@PreAuthorize("@ss.hasPermi('system:mgt:add')")
    @Log(title = "人员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonMgt personMgt)
    {
        return toAjax(personMgtService.insertPersonMgt(personMgt));
    }

    /**
     * 修改人员管理
     */
    //@PreAuthorize("@ss.hasPermi('system:mgt:edit')")
    @Log(title = "人员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonMgt personMgt)
    {
        return toAjax(personMgtService.updatePersonMgt(personMgt));
    }

    /**
     * 删除人员管理
     */
    //@PreAuthorize("@ss.hasPermi('system:mgt:remove')")
    @Log(title = "人员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(personMgtService.deletePersonMgtByIds(ids));
    }
}
